﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace DelegateTest1
{
   
    public class BaseClass
    {
        public BaseClass()
        {
        }

        public delegate void ImportProgress(int total, int current);

        public event ImportProgress Importing; 
        
        public event EventHandler StartImport;
        public event EventHandler EndImport;
        public event EventHandler CancelImport;

        public bool IsStop { get; set; } = false;


        public void DoSomeThing()
        {
            StartImport.Invoke(100, new EventArgs());

            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(100);
                if (!IsStop)
                {
                    Importing(100, i);
                }
                else
                {
                    i--;
                }
            }

            EndImport.Invoke("结束", new EventArgs());

        }

        public void Cancle()
        {
            this.IsStop = !IsStop;
            CancelImport.Invoke(IsStop ? "继续" : "暂停", new EventArgs());
        }
    }
}
